<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.resource.ResourceComInfo" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="java.security.MessageDigest" %>
<%
    JSONObject jsonData = new JSONObject();
    User user = HrmUserVarify.getUser(request, response);
    String userid = user.getUID() + "";
    //String url = "https://zc.wxidg.com:442/loginOA";
    String url = "https://a8.fway.vip/loginOA";
    try {
        ResourceComInfo resourceComInfo = new ResourceComInfo();
        String loginid = Util.null2String(resourceComInfo.getLoginID(userid));
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        String inputString = "Fairway2024!@" + loginid + timestamp;
        // 初始化MessageDigest对象
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        // 将要加密的字符串转换成字节数组
        byte[] messageBytes = inputString.getBytes(StandardCharsets.UTF_8);
        // 更新摘要信息
        md.update(messageBytes);
        // 计算哈希值
        byte[] hashBytes = md.digest();
        // 将哈希值转换成十六进制字符串便于查看
        StringBuilder sb = new StringBuilder();
        for (byte b : hashBytes) {
            sb.append(String.format("%02x", b));
        }
        String accessToken = sb.toString();
        jsonData.put("loginid", loginid);
        jsonData.put("timestamp", timestamp);
        jsonData.put("accessToken", accessToken);
        jsonData.put("url", url);
    } catch (Exception e) {
        e.printStackTrace();
    }
    out.print(jsonData.toJSONString());
%>
<%!

%>